<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>login</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js"></script>
    <script th:inline="javascript">
        function login() {
            var name = $("#nameId").val();
            var passcode = $("#passcodeId").val();
            var data = '{"name":"'+ name +'","password":"'+ passcode +'"}';
            console.log(">>>>>>>>data:" + data);
            if (null === name || null === passcode || name === "" || passcode === "") {
                return;
            }
            $.ajax({
                type: 'POST',
                url: "/login",
                data: data,
                //dataType: "json",
                contentType: "application/json;charset=UTF-8",
                success: function (msg) {
                    if (msg.code === 200){
                        console.log(">>>>>>>>登录成功：" + msg.code);
                        window.location.href = '/user/page/' + msg.user.id;
                    } else {
                        alert("登录失败！");
                    }
                },
                error: function (e) {
                    console.log('>>>>>>>>错误');
                }
            });
        }
    </script>
</head>
<body>

    <form th:id="loginForm" th:accept-charset="utf-8">
        <table>
            <tbody>
            <tr>
                <td>【name】：</td>
                <td><input th:id="nameId" th:name="name" th:type="text"/></td>
                <td></td>
            </tr>
            <tr>
                <td>【passcode】：</td>
                <td><input th:id="passcodeId" th:name="password" th:type="password"/></td>
                <td></td>
            </tr>
            </tbody>
            <tfoot>
            <tr>
                <td></td>
                <td><a th:onclick="login()"><input th:id="submitId" th:type="button" th:value="登录"></a></td>
                <td></td>
            </tr>
            </tfoot>
        </table>
    </form>

</body>
</html>